package com.lw.lambda;

/**
 * @author LW
 * @2020/8/17 11:20
 */
public class TestLambda2 {

    static class Love implements ILove{
        @Override
        public void love(int a) {
            System.out.println("i love you"+a);
        }


    }

    public static void main(String[] args) {
        ILove love = new Love();
        love.love(2);
        love = new Love();
        love.love(3);

        class Love implements ILove{

            @Override
            public void love(int a) {
                System.out.println("i love you"+a);
            }
        }
        love = new Love();
        love.love(4);

        love = new ILove() {
            @Override
            public void love(int a) {
                System.out.println("i love you"+a);
            }
        };
        love.love(5);

        //lambda简化   从带参数的括号开始保存
        love = (int a)->{
            System.out.println("i love you"+a);
        };

        //简化参数
        love = (a)->{//多个参数不能去掉小括号
            System.out.println("i love you"+a);
        };
        //简化括号
        love = a->{
            System.out.println("i love you"+a);
            System.out.println("i love you too");//多行输出不能简化大括号
        };
        //简化去掉大括号
        love = a-> System.out.println("i love you"+a);
        love.love(6);
    }

}

interface ILove{
    void love(int a);//只能有一个方法
}

class Love implements ILove{

    @Override
    public void love(int a) {
        System.out.println("i love you"+a);
    }
}